﻿using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Shuba.Model;
using System;

namespace Shuba.Data
{
    public class BranchNipSOMap
    {
        public BranchNipSOMap()
        {
        }
      
        public List<BranchNipSOMapInfo> GetList(string value)
        {
            List<BranchNipSOMapInfo> list = new List<BranchNipSOMapInfo>();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"
                               SELECT 
                                    A.BRANCH_ID, B.BRANCH_NAME, A.AO_CODE, A.NIP,
                                    ISNULL(C.MS_STD_NAME,'') AS USER_TYPE, A.MOBILE_PHONE, 
                                    A.MAC_ADDRESS, A.OLD_MAC_ADDRESS, A.EFF_DATE_MUTATION,
                                    A.ENTRY_BY, A.ENTRY_DATE, A.UPDATE_BY, A.UPDATE_DATE, A.AO_TYPE	
                                FROM TBL_MS_BRANCH_NIP_SO A 
                                INNER JOIN 
                                (
	                                SELECT BRANCH_ID, BRANCH_NAME FROM TBL_MS_BRANCH 
	                                UNION 
	                                SELECT REGIONAL_ID AS BRANCH_ID, REGIONAL_NAME AS BRANCH_NAME FROM TBL_MS_REGIONAL
	                                UNION
	                                SELECT CLUSTER_ID AS BRANCH_ID, CLUSTER_NAME AS BRANCH_NAME FROM TBL_MS_CLUSTER
                                    UNION
	                                SELECT HO_ID AS BRANCH_ID, HO_NAME AS BRANCH_NAME FROM TBL_MS_HO
                                ) B ON A.BRANCH_ID = B.BRANCH_ID 
                                LEFT OUTER JOIN (SELECT MS_STD_ID, MS_STD_NAME FROM dbo.TBL_MS_STANDARD WHERE MS_STD_GRP_ID = 10) C ON A.USER_TYPE = C. MS_STD_ID
                                WHERE 
                                    (A.NIP LIKE '' + @PARAM + '' OR B.BRANCH_NAME LIKE '%' + @PARAM + '%' OR B.BRANCH_ID LIKE '%' + @PARAM + '%' ) 
                                ORDER BY A.NIP");
            db.AddInParameter(cmd, "@PARAM", DbType.String, value);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    list.Add(new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetString(6), dr.GetString(7), dr.GetDateTime(8), dr.GetString(9), dr.GetDateTime(10), dr.GetString(11), dr.GetDateTime(12), dr.GetString(13)));
                }
                dr.Close();
            }
            return list;
        }

        public List<BranchNipSOMapInfo> GetListPaging(string value, int currPage, int dataPerPage)
        {
            int barisAwal = 1 + (currPage - 1) * dataPerPage;
            int barisAkhir = barisAwal + dataPerPage - 1;
            List<BranchNipSOMapInfo> list = new List<BranchNipSOMapInfo>();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"
                        SELECT * FROM
                        (
                           SELECT ROW_NUMBER() OVER (ORDER BY A.NIP) AS Row, 
                                A.BRANCH_ID, B.BRANCH_NAME, A.AO_CODE, A.NIP,
                                ISNULL(C.MS_STD_NAME,'') AS USER_TYPE, A.MOBILE_PHONE, 
                                A.MAC_ADDRESS, A.OLD_MAC_ADDRESS, A.EFF_DATE_MUTATION,
                                A.ENTRY_BY, A.ENTRY_DATE, A.UPDATE_BY, A.UPDATE_DATE, A.AO_TYPE	
                            FROM TBL_MS_BRANCH_NIP_SO A 
                            INNER JOIN 
                            (
                                SELECT BRANCH_ID, BRANCH_NAME FROM TBL_MS_BRANCH 
                                UNION 
                                SELECT REGIONAL_ID AS BRANCH_ID, REGIONAL_NAME AS BRANCH_NAME FROM TBL_MS_REGIONAL
                                UNION
                                SELECT CLUSTER_ID AS BRANCH_ID, CLUSTER_NAME AS BRANCH_NAME FROM TBL_MS_CLUSTER
                                UNION
                                SELECT HO_ID AS BRANCH_ID, HO_NAME AS BRANCH_NAME FROM TBL_MS_HO
                            ) B ON A.BRANCH_ID = B.BRANCH_ID 
                            LEFT OUTER JOIN (SELECT MS_STD_ID, MS_STD_NAME FROM dbo.TBL_MS_STANDARD WHERE MS_STD_GRP_ID = 10 OR MS_STD_GRP_ID = 64 GROUP BY MS_STD_ID, MS_STD_NAME) C ON A.USER_TYPE = C. MS_STD_ID
                            WHERE 
                                (A.NIP LIKE @PARAM OR B.BRANCH_NAME LIKE @PARAM OR B.BRANCH_ID LIKE @PARAM)                            
                        ) AS LogWithRowNumbers 
                        WHERE  Row >= @BARIS_AWAL AND Row <= @BARIS_AKHIR");
            db.AddInParameter(cmd, "@PARAM", DbType.String, "%" + value + "%");
            db.AddInParameter(cmd, "@BARIS_AWAL", DbType.Int32, barisAwal);
            db.AddInParameter(cmd, "@BARIS_AKHIR", DbType.Int32, barisAkhir);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    list.Add(new BranchNipSOMapInfo(dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetString(6), dr.GetString(7), dr.GetString(8), dr.GetDateTime(9), dr.GetString(10), dr.GetDateTime(11), dr.GetString(12), dr.GetDateTime(13), dr.GetString(14)));
                }
                dr.Close();
            }
            return list;
        }

        public int GetRowListPaging(string value)
        {
            int jmlRow = 0;
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"
                           SELECT COUNT(1) AS jmlData	
                                FROM TBL_MS_BRANCH_NIP_SO A 
                                INNER JOIN 
                                (
                                    SELECT BRANCH_ID, BRANCH_NAME FROM TBL_MS_BRANCH 
                                    UNION 
                                    SELECT REGIONAL_ID AS BRANCH_ID, REGIONAL_NAME AS BRANCH_NAME FROM TBL_MS_REGIONAL
                                    UNION
                                    SELECT CLUSTER_ID AS BRANCH_ID, CLUSTER_NAME AS BRANCH_NAME FROM TBL_MS_CLUSTER
                                    UNION
                                    SELECT HO_ID AS BRANCH_ID, HO_NAME AS BRANCH_NAME FROM TBL_MS_HO
                                ) B ON A.BRANCH_ID = B.BRANCH_ID 
                                LEFT OUTER JOIN (SELECT MS_STD_ID, MS_STD_NAME FROM dbo.TBL_MS_STANDARD WHERE MS_STD_GRP_ID = 10 OR MS_STD_GRP_ID = 64 GROUP BY MS_STD_ID, MS_STD_NAME) C ON A.USER_TYPE = C. MS_STD_ID
                            WHERE 
                                (A.NIP LIKE @PARAM OR B.BRANCH_NAME LIKE @PARAM OR B.BRANCH_ID LIKE @PARAM)");
            db.AddInParameter(cmd, "@PARAM", DbType.String, "%" + value + "%");

            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                    jmlRow = (int)dr["jmlData"];
                dr.Close();
            }
            return jmlRow;
        }

        public BranchNipSOMapInfo Get(string NIP)
        {
            BranchNipSOMapInfo ri = new BranchNipSOMapInfo();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE
                                FROM TBL_MS_BRANCH_NIP_SO WHERE (NIP LIKE '' + @NIP + '')");
            db.AddInParameter(cmd, "@NIP", DbType.String, NIP);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    ri = new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetDateTime(6), dr.GetString(7), dr.GetDateTime(8), dr.GetString(9), dr.GetString(10), dr.GetDateTime(11), dr.GetString(12));
                }
                dr.Close();
            }
            return ri;
        }

        public BranchNipSOMapInfo GetUMByUnit(string UnitCode)
        {
            BranchNipSOMapInfo ri = new BranchNipSOMapInfo();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"SELECT TOP 1 BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE FROM
                                (
                                    SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE
                                    FROM TBL_MS_BRANCH_NIP_SO WHERE (USER_TYPE LIKE 'UM') AND (BRANCH_ID LIKE '' + @BRANCH_ID + '') 
                                    UNION
                                    SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE 
                                    FROM TBL_MS_BRANCH_NIP_SO_TMP WHERE (USER_TYPE LIKE 'UM') AND (BRANCH_ID LIKE '' + @BRANCH_ID + '') 
                                ) X ;");
            db.AddInParameter(cmd, "@BRANCH_ID", DbType.String, UnitCode);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    ri = new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetDateTime(6), dr.GetString(7), dr.GetDateTime(8), dr.GetString(9), dr.GetString(10), dr.GetDateTime(11), dr.GetString(12));
                }
                dr.Close();
            }

            return ri;
        }

        public BranchNipSOMapInfo GetByAOCode(string AOCode, string AppCode)
        {
            BranchNipSOMapInfo ri = new BranchNipSOMapInfo();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"SELECT TOP 1 BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE 
                                FROM 
                                (
                                    SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE 
                                    FROM TBL_MS_BRANCH_NIP_SO WHERE LTRIM(RTRIM(AO_CODE)) LIKE '' + @AO_CODE + ''
                                    UNION
                                    SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, AO_TYPE 
                                    FROM TBL_MS_BRANCH_NIP_SO_TMP WHERE LTRIM(RTRIM(AO_CODE)) LIKE '' + @AO_CODE + ''
                                ) X ;");
            db.AddInParameter(cmd, "@AO_CODE", DbType.String, AOCode);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    ri = new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetDateTime(6), dr.GetString(7), dr.GetDateTime(8), dr.GetString(9), dr.GetString(10), dr.GetDateTime(11), dr.GetString(12));
                }
                dr.Close();
            }

            return ri;
        }

        public BranchNipSOMapInfo GetApprovalByID(string NIP)
        {
            BranchNipSOMapInfo ri = new BranchNipSOMapInfo();
            Database db = DBConnection.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(@"SELECT BRANCH_ID, AO_CODE, NIP, USER_TYPE, MOBILE_PHONE, ENTRY_BY, ENTRY_DATE, UPDATE_BY, UPDATE_DATE, 
                                ACT_TYPE, IS_DOWNLOADED, DOWNLOAD_BY, DOWNLOAD_DATE, MAC_ADDRESS, OLD_MAC_ADDRESS, EFF_DATE_MUTATION, IS_MIGRATION, AO_TYPE
                                FROM TBL_MS_BRANCH_NIP_SO_TMP WHERE NIP LIKE '' + @NIP + ''");
            db.AddInParameter(cmd, "@NIP", DbType.String, NIP);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    ri = new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetDateTime(6), dr.GetString(7), dr.GetDateTime(8), dr.GetString(9), dr.GetString(10), dr.GetString(11), dr.GetDateTime(12), dr.GetString(13), dr.GetString(14));
                }
                dr.Close();
            }

            return ri;
        }

        public List<BranchNipSOMapInfo> GetListApproval(string value, string UpdateBy, string AppCodeList)
        {
            List<BranchNipSOMapInfo> list = new List<BranchNipSOMapInfo>();
            Database db = DBConnection.CreateDatabase();
            string sql = @"SELECT * FROM
                            (
                                SELECT 
                                     A.BRANCH_ID, ISNULL(B.BRANCH_NAME, '') AS BRANCH_NAME, ISNULL(A.AO_CODE,'') AS AO_CODE, A.NIP, ISNULL(C.MS_STD_NAME,'') AS USER_TYPE, A.MOBILE_PHONE,
                                     A.ENTRY_BY, A.ENTRY_DATE, A.UPDATE_BY, A.UPDATE_DATE, A.ACT_TYPE, ISNULL(D.USER_NAME,'') AS USER_NAME,
                                     A.MAC_ADDRESS, A.OLD_MAC_ADDRESS, A.EFF_DATE_MUTATION, A.IS_MIGRATION, A.AO_TYPE
                                FROM TBL_MS_BRANCH_NIP_SO_TMP A 
		                            LEFT OUTER JOIN 
		                            (
			                            SELECT BRANCH_ID, BRANCH_NAME FROM TBL_MS_BRANCH 
			                            UNION 
			                            SELECT REGIONAL_ID AS BRANCH_ID, REGIONAL_NAME AS BRANCH_NAME FROM TBL_MS_REGIONAL
			                            UNION
			                            SELECT CLUSTER_ID AS BRANCH_ID, CLUSTER_NAME AS BRANCH_NAME FROM TBL_MS_CLUSTER
                                        UNION
	                                    SELECT HO_ID AS BRANCH_ID, HO_NAME AS BRANCH_NAME FROM TBL_MS_HO
		                            ) B ON A.BRANCH_ID = B.BRANCH_ID 
		                            LEFT OUTER JOIN (SELECT MS_STD_ID, MS_STD_NAME FROM TBL_MS_STANDARD WHERE MS_STD_GRP_ID = 10 OR MS_STD_GRP_ID = 64 GROUP BY MS_STD_ID, MS_STD_NAME) C ON A.USER_TYPE = C.MS_STD_ID 
		                            LEFT OUTER JOIN (SELECT NIP, USER_NAME FROM V_USER WHERE APP_ID IN ('SPADA','SPAWEB') GROUP BY NIP, USER_NAME)D ON A.NIP = D.NIP 
                            ) X 
                            WHERE 
                                BRANCH_NAME LIKE '%' + @BRANCH_NAME + '%' 
                                AND (RTRIM(UPDATE_BY) <> '' + @UPDATE_BY + '') 
                            ORDER BY BRANCH_NAME";
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@BRANCH_NAME", DbType.String, value);
            db.AddInParameter(cmd, "@UPDATE_BY", DbType.String, UpdateBy);
            using (IDataReader dr = db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    list.Add(new BranchNipSOMapInfo(dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5), dr.GetString(6), dr.GetDateTime(7), dr.GetString(8), dr.GetDateTime(9), dr.GetString(10), dr.GetString(11), dr.GetString(12), dr.GetString(13), dr.GetDateTime(14), dr.GetString(15), dr.GetString(16)));
                }
                dr.Close();
            }
            return list;
        }
     
        public void Save(BranchNipSOMapInfo BranchNipSOMap)
        {
            Database db = DBConnection.CreateDatabase();

            string sql = @" DECLARE @CURRENT_MAC_ADDRESS VARCHAR(50),
                                       @NEW_MAC_ADDRESS VARCHAR(50),
                                       @NEW_OLD_MAC_ADDRESS VARCHAR(50)

                            SET @NEW_MAC_ADDRESS = @MAC_ADDRESS
                            SET @NEW_OLD_MAC_ADDRESS = @OLD_MAC_ADDRESS

                            SELECT @CURRENT_MAC_ADDRESS = MAC_ADDRESS 
                            FROM TBL_MS_BRANCH_NIP_SO WHERE NIP = @NIP

                            IF ((@ACT_TYPE = 'UPLOAD') AND (REPLACE(@CURRENT_MAC_ADDRESS,'-','') != REPLACE(@NEW_MAC_ADDRESS,'-','')))
                                    BEGIN 
                                    SET @NEW_OLD_MAC_ADDRESS = @CURRENT_MAC_ADDRESS
                            END                                 
                                
                            UPDATE [TBL_MS_BRANCH_NIP_SO_TMP]
                               SET [BRANCH_ID] = LEFT(@BRANCH_ID,6)
                                  ,[AO_CODE] = LEFT(@AO_CODE,5)
                                  ,[NIP] = LEFT(@NIP,9)
                                  ,[USER_TYPE] = LEFT(@USER_TYPE,10)
                                  ,[MOBILE_PHONE] = LEFT(@MOBILE_PHONE,15)
                                  ,[ENTRY_BY] = @ENTRY_BY
                                  ,[ENTRY_DATE] = @ENTRY_DATE
                                  ,[UPDATE_BY] = @UPDATE_BY
                                  ,[UPDATE_DATE] = @UPDATE_DATE
                                  ,[MAC_ADDRESS] = @NEW_MAC_ADDRESS
                                  ,[OLD_MAC_ADDRESS] = @NEW_OLD_MAC_ADDRESS 
                                  ,[IS_MIGRATION] = @IS_MIGRATION
                                  ,[AO_TYPE] = @AO_TYPE
                            WHERE (NIP LIKE '' + LEFT(@NIP,9) + '') ;
                                IF @@ROWCOUNT = 0
                            INSERT INTO [TBL_MS_BRANCH_NIP_SO_TMP] 
                                        ([BRANCH_ID],[AO_CODE],[NIP],
                                        [USER_TYPE],[MOBILE_PHONE],[ENTRY_BY],
                                        [ENTRY_DATE],[UPDATE_BY],[UPDATE_DATE],
                                        [ACT_TYPE],[MAC_ADDRESS],[OLD_MAC_ADDRESS],[IS_MIGRATION],[AO_TYPE]) 
                            VALUES (LEFT(@BRANCH_ID,6), LEFT(@AO_CODE,5), LEFT(@NIP,9), 
                                    LEFT(@USER_TYPE,10), LEFT(@MOBILE_PHONE,15), @ENTRY_BY, 
                                    @ENTRY_DATE, @UPDATE_BY, @UPDATE_DATE, @ACT_TYPE,
                                    @NEW_MAC_ADDRESS, @NEW_OLD_MAC_ADDRESS, @IS_MIGRATION, @AO_TYPE)";
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@BRANCH_ID", DbType.String, BranchNipSOMap.BRANCH_ID);
            db.AddInParameter(cmd, "@AO_CODE", DbType.String, BranchNipSOMap.AO_CODE);
            db.AddInParameter(cmd, "@NIP", DbType.String, BranchNipSOMap.NIP);
            db.AddInParameter(cmd, "@USER_TYPE", DbType.String, BranchNipSOMap.USER_TYPE);
            db.AddInParameter(cmd, "@MOBILE_PHONE", DbType.String, BranchNipSOMap.HP);
            db.AddInParameter(cmd, "@ENTRY_BY", DbType.String, BranchNipSOMap.ENTRY_BY);
            db.AddInParameter(cmd, "@ENTRY_DATE", DbType.DateTime, BranchNipSOMap.ENTRY_DATE);
            db.AddInParameter(cmd, "@UPDATE_BY", DbType.String, BranchNipSOMap.UPDATE_BY);
            db.AddInParameter(cmd, "@UPDATE_DATE", DbType.DateTime, BranchNipSOMap.UPDATE_DATE);
            db.AddInParameter(cmd, "@ACT_TYPE", DbType.String, BranchNipSOMap.ACT_TYPE);
            db.AddInParameter(cmd, "@MAC_ADDRESS", DbType.String, BranchNipSOMap.MAC_ADDRESS);
            db.AddInParameter(cmd, "@IS_MIGRATION", DbType.String, BranchNipSOMap.IS_MIGRATION ?? "0");
            db.AddInParameter(cmd, "@AO_TYPE", DbType.String, BranchNipSOMap.AO_TYPE);
            if (BranchNipSOMap.ACT_TYPE == "UPLOAD")
            {
                db.AddInParameter(cmd, "@OLD_MAC_ADDRESS", DbType.String, "");
            }
            else
            {
                db.AddInParameter(cmd, "@OLD_MAC_ADDRESS", DbType.String, BranchNipSOMap.OLD_MAC_ADDRESS);
            }

            db.ExecuteNonQuery(cmd);
        }

        public int Approve(string NIP, string ActType, string UpdateBY, DateTime UpdateDate)
        {
            int status = 0;
            try
            {
                Database db = DBConnection.CreateDatabase();
                DbCommand cmd = db.GetStoredProcCommand("BRANCH_NIP_SO_APPROVAL");

                db.AddInParameter(cmd, "@NIP", DbType.String, NIP);
                db.AddInParameter(cmd, "@ACT_TYPE", DbType.String, ActType);
                db.AddInParameter(cmd, "@UPDATE_BY", DbType.String, UpdateBY);
                db.AddInParameter(cmd, "@UPDATE_DATE", DbType.DateTime, UpdateDate);

                status = db.ExecuteNonQuery(cmd);
            }
            catch (Exception) { }
            return status;
        }

        public int Reject(string NIP)
        {
            int status = 0;
            try
            {
                Database db = DBConnection.CreateDatabase();

                string sql;
                DbCommand cmd;

                sql = String.Format("DELETE FROM TBL_MS_BRANCH_NIP_SO_TMP WHERE NIP LIKE '{0}'", NIP);
                cmd = db.GetSqlStringCommand(sql);

                status = db.ExecuteNonQuery(cmd);
            }
            catch (Exception) { }
            return status;
        }
    }
}
